package com.example.demo.controller;

import com.aliyun.oss.model.MultipartUpload;
import com.example.demo.pojo.Result;
import com.example.demo.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
public class UploadController {
    @Autowired
    AliOSSUtils aliOSSUtils;

    @PutMapping("/upload")
    public Result upload(MultipartFile image) throws Exception {
        log.info("文件上传,文件名:{}" , image.getOriginalFilename());
        String url = aliOSSUtils.upload(image);
        log.info("文件上传完成，访问的url:{}",url );
        return Result.success(url);//可以不创建Result对象直接调用方法（static 静态方法）



    }
}
